package org.example.route.controller.UserController;



import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.route.model.dto.OrderGenerateDTO;
import org.example.route.model.dto.PayOrderDTO;
import org.example.route.model.dto.PriceQueryDTO;
import org.example.route.model.dto.SeatShowDTO;
import org.example.route.model.pojo.Result;
import org.example.route.model.vo.IntoDetailVO;
import org.example.route.model.vo.PriceVO;
import org.example.route.model.vo.SeatShowVO;
import org.example.route.service.BuyService;
import org.example.route.service.PriceService;
import org.example.route.service.TrainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/buy")
//订票系统
@Slf4j
@Tag(name = "用户购买")
//用来查询站点的车票
public class BuyController {

    @Autowired
    private BuyService buyService;
    @Autowired
    private PriceService priceService;
    @Autowired
    private TrainService trainService;


    //TODO 订票系统
    //进入详情页面
    @Operation(summary = "进入详情页面")
    @PostMapping("/intoDetail")
    /**完成一测**/
    //查路线
    public Result<IntoDetailVO> intoDetail(@RequestBody PriceQueryDTO priceQueryDTO)
    {

        log.info("进入详情页面,{}",priceQueryDTO);
        IntoDetailVO intoDetailVO = buyService.intoDetail(priceQueryDTO);
        return Result.success(intoDetailVO);

    }

    /**
     *
     * 完成一测，修复gradeName错配的bug
     *
     * **/
    @Operation(summary = "进一步查询")
    @PostMapping("/list")
    public Result<List<PriceVO>> list(@RequestBody PriceQueryDTO priceQueryDTO)
    {
        log.info("在详情页面再深度查询,{}",priceQueryDTO);
        List<PriceVO> priceVOList = priceService.list(priceQueryDTO);
        return Result.success(priceVOList);
    }

    /**完成一测**/
    @Operation(summary = "显示座位列表")
    @PostMapping("/showSeat")
    public Result<List<SeatShowVO>> showSeat(@RequestBody SeatShowDTO seatShowDTO)
    {
        //显示用户的座位
        log.info("显示用户的座位,{}",seatShowDTO);

        List<SeatShowVO> seatShowVOList = trainService.listTheSeat(seatShowDTO);


        return Result.success(seatShowVOList);
    }

    //选座位并生成订单和购物车
    //传回前端购物车代码
    /**完成二测**/
    @Operation(summary = "选座位并生成订单和购物车")
    @PostMapping("/generateOrderAndShopping")
    public Result generateOrder(@RequestBody OrderGenerateDTO orderGenerateDTO)
    {
        log.info("选座位并生成订单和购物车,{}",orderGenerateDTO);
        buyService.generateOrderAndShopping(orderGenerateDTO);
        //生成后之后直接在前端跳转购物车页面
        return Result.success();


    }

    //支付订单并删去购物车的内容

    /**完成二测**/
    @Operation(summary = "支付订单并删去购物车内容")
    @PostMapping("/payOrder")
    public Result payOrder(@RequestBody PayOrderDTO payOrderDTO)
    {
     log.info("支付订单并删去购物车内容,{}",payOrderDTO);
     buyService.payOrder(payOrderDTO);
     return Result.success();
    }











}
